package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ysd.dao.impl.NewscategoryDaoImpl;
import com.ysd.dao.impl.NewsdetailsDaoImpl;
import com.ysd.entity.Newscategory;
import com.ysd.entity.Newsdetails;

public class NewsDetailServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		NewscategoryDaoImpl newscategoryDao = new NewscategoryDaoImpl();
		List<Newscategory> newscategoryList = newscategoryDao.getNewscategory();
		request.setAttribute("newscategoryList", newscategoryList);
		
		int nid=Integer.parseInt(request.getParameter("newsId"));
		NewsdetailsDaoImpl newsdetailsDao= new NewsdetailsDaoImpl();
		List<Newsdetails> newsdetails= newsdetailsDao.getNewsdetails(nid);
		request.setAttribute("newsdetails", newsdetails);
		
		int neid=Integer.parseInt(request.getParameter("newsId"));
		NewsdetailsDaoImpl newsContentDao= new NewsdetailsDaoImpl();
		List<Newsdetails> newsContentLst =newsContentDao.getNewsContent(neid);
		request.setAttribute("newsContentLst", newsContentLst);
		
		
		//上一条
		int aId = Integer.parseInt(request.getParameter("newsId"));
		NewsdetailsDaoImpl Details = new NewsdetailsDaoImpl();
		List<Newsdetails> seList = Details.skipNewDetails(aId);
		request.setAttribute("seList", seList);
				
		//下一条
		int bId = Integer.parseInt(request.getParameter("newsId"));
		NewsdetailsDaoImpl skipDetails = new NewsdetailsDaoImpl();
		List<Newsdetails> skipList = skipDetails.skipNewsDetails(bId);
		request.setAttribute("skipList", skipList);

		
		
		request.getRequestDispatcher("article_list_content.jsp").forward(request, response);//转发
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
